/**
 * @file esp_lcd_backlight.h
 */

#pragma once

#include <stdbool.h>
#include "esp_err.h"

typedef struct {
    bool output_invert;
    int gpio_num; // see gpio_num_t
    int timer_idx;   // ledc_timer_t
    int channel_idx; // ledc_channel_t
} esp_lcd_backlight_config_t;

typedef void* esp_lcd_backlight_handle_t;

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @brief Create new backlight controller
 *
 * @param[in]   config      Configuration structure of backlight controller
 * @param[out]  bckl_handle Display backlight controller handle
 * @return  error result
 */
esp_err_t esp_lcd_backlight_create(const esp_lcd_backlight_config_t* config, esp_lcd_backlight_handle_t* bckl_handle);

/**
 * @brief Set backlight
 *
 * Brightness parameter can be 0-100 for PWM controlled backlight.
 * GPIO controlled backlight (ON/OFF) is turned off witch value 0 and turned on with any positive value.
 *
 * @param bckl_handle            Backlight controller handle
 * @param[in] brightness_percent Brightness in [%]
 * @return  error result
 */
esp_err_t esp_lcd_backlight_set(esp_lcd_backlight_handle_t bckl_handle, uint8_t brightness_percent);

/**
 * @brief Set backlight
 *
 * Brightness parameter can be 0-100 for PWM controlled backlight.
 * GPIO controlled backlight (ON/OFF) is turned off witch value 0 and turned on with any positive value.
 *
 * @param bckl_handle            Backlight controller handle
 * @return  error result
 */
esp_err_t esp_lcd_backlight_delete(esp_lcd_backlight_handle_t bckl_handle);

#ifdef __cplusplus
}
#endif